package fr.enseirbmatmeca.apms.spring.model.user;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.annotations.GenericGenerator;

@SuppressWarnings("serial")
@Entity
/**
 * 
 * <strong>id</strong> reference to the unique ID of the User
 * <strong>login</strong> reference to the unique login of the User, this field as the username for log in matters
 * <strong>password</strong> reference to the encoded password TODO the security stuff
 * <strong>firstName</strong> reference to the first name of the User if known to write full name with firstName
 * <strong>lastName</strong> reference to the first name of the User if known to write full name with lastName
 * <strong>title</strong> reference to the gender of the User if known to use Mr. or Mme.
 * <strong>type</strong> reference to the type of the User : 
 * <ul>
 * 	<li><strong>ADMINISTRATOR<strong> has the right to do modify every projects and setup them</li>
 * 	<li><strong>STUDENT<strong> has the right to see his projects, send reports for them and check status / deadlines</li>
 * 	<li><strong>TUTOR<strong> has the right to report marks and is shown as tutor for the project in order to receive reports and change project properties he is assigned to</li>
 * 	<li><strong>REPORTER<strong> has the right to report marks for the projects he has been assigned to</li>
 * </ul>
 * 
 *  IN PRACTICE :
 *  
 * <ul>
 * 	<li><strong>ADMINISTRATOR<strong> has the right on everything</li>
 * 	<li><strong>USER<strong> has the corresponding right to ProjectGroup references</li>
 * </ul>
 * 
 * 
 * if a TUTOR is also a REPORTER for another project, he will able to
 * modify the Project from a ProjectGroup only if he is part of the TUTOR list ( and not STUDENT list or REPORTER list)
 *
 * 
 * @author coudar
 *
 */
public class User implements Serializable {
	
	public static final int ADMINISTRATOR = 0;
	public static final int USER = 1;
	
	public static final int TITLE_MAN = 0;
	public static final int TITLE_WOMAN = 1;


	private String id;
	private String login;
	private String password;
	private String LastName;
	private String firstName;
	private int title;
	private int type;
	private boolean casUser; // if user is connecting from CAS
	private String promotion; // promotion in which the user takes part
	
	public User() {} 
	
	public User(String login, String password) {
		this.login = login;
		this.password = password;
	}

	@Column
	public String getFirstName() {
		return firstName;
	}

	@Id
	@GeneratedValue(generator="system-uuid")
	@GenericGenerator(name="system-uuid", strategy = "uuid")
	@Column(unique = true, nullable = false)
	public String getId() {
		return this.id;
	}
	
	@Column
	public String getLastName() {
		return LastName;
	}
	
	@Column(nullable = false)
	public String getLogin() {
		return login;
	}
	
	@Column
	public String getPassword() {
		return password;
	}
	@Column
	public int getTitle() {
		return title;
	}

	@Column(nullable = false, columnDefinition = "int default "+USER)
	public int getType() {
		return type;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setLastName(String lastName) {
		LastName = lastName;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setTitle(int title) {
		this.title = title;
	}

	public void setType(int type) {
		this.type = type;
	}

	//default to false
	@Column(nullable = false, columnDefinition = "tinyint(1) default 0")
	public boolean isCasUser() {
		return casUser;
	}

	public void setCasUser(boolean casUser) {
		this.casUser = casUser;
	}

	@Column
	public String getPromotion() {
		return promotion;
	}

	public void setPromotion(String promotion) {
		this.promotion = promotion;
	}
	
	
}
